<template>
	<ul class="store-items-ul">
    	<li class="store-item" v-for="appoint in appoints">
      		<TableItemForAppoint :title="appoint.name" :subDetailOne="'时间:'+appoint.time" :subDetailTwo="'地址:'+appoint.address" :subDetailThree="'电话:'+appoint.tel" v-on:itemClicked="goMyAppoint(appoint.id)"></TableItemForAppoint>
    	</li>
	</ul>
</template>
<script>
import Config from 'common/script/config.js'
import TableItemForAppoint from 'components/tableItemForAppoint/tableItemForAppoint'
import moment from 'moment'
export default {
	name: 'appointTab',
	data () {
		return {
			appoints: [],
			openId: '',
			userId: ''
		}
	},
	methods: {
		goMyAppoint: function (appointId) {
	    	window.location.href = 'appoint.html?flag=expired&appointId=' + appointId + '&userId=' + this.userId + '&openId=' + this.openId
	    },
	    appointDate: function (dateArray) {
	    	var array = []
	    	for (var i = 0; i < dateArray.length; i++) {
	    		var item = dateArray[i]
	    		var newItem = {
	    			'name': item.name,
	    			'time': moment(item.appointmentTime).format('YYYY-MM-DD'),
	    			'address': item.address,
	    			'tel': item.tel,
	    			'id': item.id
	    		}
	    		array.push(newItem)
	    	}
	    	this.appoints = array
	    }
	},
	created: function () {
		this.openId = Config.getReqParam('wechatid')
		this.userId = Config.getReqParam('userid')
	    this.$http.post('/freescan/free/getAllFreeScannerAppointmentByDate', {
	    	'openId': this.openId,
	    	'userId': this.userId
	    }).then((response) => {
	    	this.loading = false
	    	response = response.body
	    	console.log(response)
	    	this.appointDate(response.body.appointmentBefore)
	    })
	},
	components: {
		TableItemForAppoint
	}
}
</script>
<style>
	
</style>